﻿#include <iostream>
#include <iomanip>
#include "color_print.h"
#include "roomPage.h"
using namespace std;

roomPage::roomPage() { };

roomPage::roomPage(ROOM_NUMBER room, string name, string roleName, int roleId, vector<string> say) 
	:role(roleName, say, roleId), name(name), room(room) {};


roomPage::roomPage(ROOM_NUMBER room, string name, double hp, double atk, string roleName, vector<string> say, int roleId)
	:role(hp, atk, roleName, say, roleId), name(name), room(room) {};

void roomPage::updatePage(Hero& hero) {
	int choice ;
	const char* chat = "1.交谈  2.攻击  3.商店  4.移动  5.保存  6. 背包  7.任务  8.退出";
	COLOR_PRINT(chat, 2);
	if(cin >> choice){
	
		switch (choice) {
		case 1: {
			if (role.get_id() <= 1) {
				if (hero.isFinishedTask(id)) {
					cout << "你已经和他对话过了哦" << endl;;
					system("pause");
				}
				else {
					role.chat_Hero();
					if (hero.nowTask() == id) {
						hero.add_Goods(role.get_id() + 1, 1);
						hero.finishTask();
					}
				}
			}
			else {
				role.chat_Hero();
			}
			break;
		}
		case 2: {
			if (role.get_id() > 1) {
				Page* fp = new fightPage(role);
				load(*fp, hero);
				delete fp;
				changeRoom(room);
			}
			else {
				cout << "无法攻击" << endl;
				system("pause");
			}
			break;
		}
		case 3: {
			Page* fp = new StorePage();
			load(*fp, hero);
			delete fp;
			break;
		}
		case 4: {
			Page* fp = new MapPage(room);
			load(*fp, hero);
			ROOM_NUMBER pos = static_cast<ROOM_NUMBER>(fp->get_position());
			changeRoom(pos);
			delete fp;
			break;
		}
		case 5: {
			Save::saveHero(hero);
			Save::saveRoom(*this);
			break;
		}
		case 6: {
			Page* fp = new BagPage();
			load(*fp, hero);
			delete fp;
			break;
		}
		case 7: {
			hero.showTask();
			break;
		}
		case 8: {
			exit(0);
			break;
		}
		default: {
			cout << "不合法的输入" << endl;
			//cin >> choice;
			//stringstream ss(choice);
			break;
		}
		}
	}
	else {
		cin.clear();
		char ch;
		cin.get(ch);
		const char* cinError = "输入错误，请重新输入";
		COLOR_PRINT(cinError, 4);
		system("pause");
	}
	
	
};
bool roomPage::isquitPage(Hero& hero) {
	return false;
};
void roomPage::drawPage(Hero& hero) {
	system("cls");
	string s = "欢迎来到";
	COLOR_PRINT_NOENDL(s, 1);
	cout<< name << endl;

	s = "姓名：";
	COLOR_PRINT_NOENDL(s, 1);
	//产生128输出
	cout /*<< ios::right << setw(20)*/ << role.get_name() << endl;

	s = "您的姓名：";
	COLOR_PRINT_NOENDL(s, 1);
	cout  << "    " << hero.get_name() << endl;

	s = "您的剩余血量： ";
	COLOR_PRINT_NOENDL(s, 1);
	cout  << hero.get_hp() << "/" << hero.get_maxhp() << endl;

	s = "法力值:";
	COLOR_PRINT_NOENDL(s, 1);
	cout  << "  " << hero.get_mp() << "/" << hero.get_maxmp() << endl;

	s = "当前等级：";
	COLOR_PRINT_NOENDL(s, 1);
	cout  << "  " << hero.get_level() << endl;

	s = "您的经验值:";
	COLOR_PRINT_NOENDL(s, 1);
	cout << "  " << hero.get_xp() << "/" << hero.get_maxxp() << endl;
};

void roomPage::changeRoom(ROOM_NUMBER position) {
	Place pl = change(position);
	name = pl.name;
	room = pl.room;
	id = room;
	if (pl.hp == 0) {
		role.change(pl.roleName, pl.say, pl.roleId);
	}
	else {
		role.change(pl.hp, pl.atk, pl.roleName, pl.say, pl.roleId);
	}
	
}
void roomPage::loadPage() {

}
int roomPage::get_position() const {
	return 0;
}